<form id="recommendForm" class="form-horizontal" action="${ctx}/admin/soft/saveRecommend.do" method="post">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h5 class="blue">软件推荐</h5>
    </div>
    <div class="modal-body">

        <!--推荐类型（此前目前只有三个，需要>动态添加，要用枚举来维护  1.精品推荐 2.应用 3.游戏 ）-->
        <div class="form-group col-xs-12 col-sm-12">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="recType">推荐类型:</label>
            <div class="col-xs-12 col-sm-4">
                <div class="clearfix">
                    <select class="form-control"  name="recType" id="recType">
                        <#list recommendTypes as recommendType>
                            <option value="${recommendType.itemValue}">
                                ${(recommendType.itemTitle)!}
                            </option>
                        </#list>
                    </select>
                </div>
            </div>
        </div>

        <!--排序号-->
        <div class="form-group col-xs-12 col-sm-12">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="sortIndex">排序:</label>
            <div class="col-xs-12 col-sm-4">
                <div class="clearfix">
                    <input type="number" name="sortIndex" id="sortIndex" class="col-xs-12 col-sm-12"  max="99999999999" value="${softRecommend.sortIndex!}"/>
                </div>
            </div>
        </div>




        <!--开始时间-->
        <div class="form-group col-xs-12 col-sm-12">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="startDate">开始时间:</label>
            <div class="col-xs-12 col-sm-4">
                <div class=" input-group">
                    <span style="position: relative; z-index: 9999;">
                    <input type="text" name="startDate" readonly id="startDate" class="col-xs-12 col-sm-12  date-picker" value="${softRecommend.startTimeShow!}" data-date-format="yyyy-mm-dd"/>
                    </span>
                    <span class="input-group-addon"> <i class="ace-icon fa fa-calendar"></i></span>
                </div>
            </div>
        </div>

        <!--过期时间-->
        <div class="form-group col-xs-12 col-sm-12">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="expiredDate">过期时间:</label>
            <div class="col-xs-12 col-sm-4">
                <div class=" input-group">
                     <span style="position: relative; z-index: 9999;">
                         <input type="text" name="expiredDate" id="expiredDate" readonly class="col-xs-12 col-sm-12  date-picker" value="${softRecommend.expiredTimeShow!}"   data-date-format="yyyy-mm-dd"/>
                     </span>
                     <span class="input-group-addon"> <i class="ace-icon fa fa-calendar"></i></span>
                </div>
            </div>
        </div>

        <!--展示端-->
        <div class="form-group col-xs-12 col-sm-12">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="terminalId">展示端:</label>
            <div class="col-xs-12 col-sm-4">
                <div class="clearfix">
                    <select class="form-control"  name="terminalId" id="terminalId" >
                        <#list terminals as terminal>
                            <option value="${terminal.id}" >
                                ${(terminal.terminalName)!}
                            </option>
                        </#list>
                    </select>
                </div>
            </div>
        </div>

        <!--推荐理由-->
        <div class="form-group col-xs-12 col-sm-12">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="recommendReason">推荐理由:</label>
            <div class="col-xs-12 col-sm-6">
                <div class="clearfix">
                    <input type="text" name="recommendReason" id="recommendReason" class="col-xs-12 col-sm-8 required" value="${softRecommend.recommendReason!}"/>
                </div>
            </div>
        </div>
        <div class="form-group">

        </div>

        <!--推荐id-->
        <input type="hidden" name="id" id="id" value="${softRecommend.id!}"/>
        <!--软件id-->
        <input type="hidden" name="softId" id="softId" value="${soft.id!}"/>
    </div>
    <div class="modal-footer center">
        <button type="submit" class="btn btn-sm btn-success"><i class="ace-icon fa fa-check"></i> 保存</button>
        <button type="button" class="btn btn-sm" data-dismiss="modal"><i class="ace-icon fa fa-times"></i> 取消</button>
    </div>
</form>
<script src="${ctx}/static/admin/assets/js/jquery.validate.js"></script>
<script src="${ctx}/static/admin/assets/js/jquery.validate.messages_zh.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#recType").val(${softRecommend.recType!});
        $("#terminalId").val(${softRecommend.terminalId!});

        $(".date-picker").datepicker({
            language : 'zh-CN',
            autoclose: true,
            todayHighlight: true
        });


        $("#recommendForm").validate({
            errorElement: 'div',
            errorClass: 'help-block',
            focusInvalid: true,
            highlight: function (e) {
                $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
            },
            success: function (e) {
                $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
                $(e).remove();
            },
            errorPlacement: function (error, element) {
                if(element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
                    var controls = element.closest('div[class*="col-"]');
                    if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
                    else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                }
                else if(element.is('.select2')) {
                    error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                }
                else if(element.is('.chosen-select')) {
                    error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                }
                else error.insertAfter(element.parent());
            },

            submitHandler: function (form) {
                if(timeCompareFailed($("#startDate").val(),$("#expiredDate").val())){
                    alert("过期时间需要大于开始时间");
                    return false;
                }
                $.ajax({
                    cache: true,
                    type: "POST",
                    url:"${ctx}/admin/soft/saveRecommend.do",
                    data:$('#recommendForm').serialize(),// 你的formid
                    async: false,
                    error: function(request) {
                        alert("Connection error");
                    },
                    success: function(data) {
                        if(data.result == "success"){
                            window.location="${refer!}";
                        }else{
                            alert(data.messages);
                        }
                    }
                });
            },
            invalidHandler: function (form) {
            }
        })


    });
</script>